function Vote_Code(){
	var buffer = new StringBuffer();
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">投票标题</div><div class="require">*</div></div><div class="ctext"><input id="vote_title" type="text" placeholder="填写投票标题" value=""/></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">投票选项</div><div class="require">*</div></div><div class="ctext"><font>1、</font><input id="option1" class="vote_option" type="text" placeholder="必填" value="" style="width:80%;"/></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname"></div><div class="require"></div></div><div class="ctext"><font>2、</font><input id="option2" class="vote_option" type="text" placeholder="必填" value="" style="width:80%;"/></div><div class="carrow"></div></div>');
	buffer.append('<div id="votepanel"></div>');
	buffer.append('<div id="addvote" class="crmsheet border-bottom addvote">新增一项</div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">单选多选</div></div><div class="ctext"><select id="vote_maxselect"><option value="1">单选</option><option value="2">最多选2项</option></select></div><div class="carrow"><img src="img/arrow.png"/></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">截止时间</div></div><div class="ctext"><select id="vote_enddate" onchange="Vote_EndTime(this)"><option value="7">一周</option><option value="14">二周</option><option value="21">三周</option><option value="30">一月(30天)</option><option value="0">自定义</option></select></div><div class="carrow"><img src="img/arrow.png"/></div></div>');
	buffer.append('<div id="senddate" class="crmsheet border-bottom hidden date"><div class="ctitle"><div class="cname"></div></div><div class="ctext"><input id="self_enddate" type="text" placeholder="选择截止时间" value="" readonly="readonly"/></div><div class="carrow"><img src="img/arrow.png"/></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">匿名投票</div></div><div class="ctext"><input id="vote_anonymous" type="checkbox" placeholder="" checked="checked" style="background-color:#cdcdcd; width:20px;"/></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">投票结果</div></div><div class="ctext"><select id="vote_result" onchange="Vote_Result(this)"><option value="1">投票人可见</option><option value="2">仅发出人可见</option><option value="3">自定义范围</option></select></div><div class="carrow"><img src="img/arrow.png"/></div></div>');
	buffer.append('<div id="vote_seeuser" class="crmsheet border-bottom hidden users" show="1" touserid="" todepartid="" tocomid=""><div class="ctitle"><div class="cname"></div></div><div class="ctext"><input id="" type="text" placeholder="选择投票结果可见人" value="" readonly="readonly"/></div><div class="carrow"><img src="img/arrow.png"/></div></div>');
	return buffer.toString();
};


function Init_Votes(){
	get("addvote").addEventListener("tap",function(){
		$("#votepanel").append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname"></div><div class="require"></div></div><div class="ctext"><font>'+($("#divmsg5 .vote_option").length+1)+'、</font><input class="vote_option" type="text" placeholder="" value="" style="width:80%;" onblur="Cal_Option()"/></div><div class="carrow" style="margin-top:3px;"><a onclick="RemoveVoteOption(this)">×</a></div></div>');
	});
	mui("#divmsg5").on("tap",".date",function(){
		obj=this;
			var t=new Date();
			if($(this).find("input").val()!="")
			{
				var year_month_day=$(this).find("input").val().split("-");
				t.setFullYear(year_month_day[0]);
				t.setMonth(year_month_day[1]-1);
				t.setDate(year_month_day[2]);
			}
			plus.nativeUI.pickDate( function(e){
				var d=e.date;
				$(obj).find("input").val((d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate()).ToDate());
			},function(e){
				console.log( "未选择日期："+e.message );
			},{date:t});
	});
	
	mui("#divmsg5").on("tap",".users",function(){
			obj10=$(this);
			OpenWindow(6,"选择员工","确定",function(){
					var str1="",str2="",str3="",headimg="";
					touserid="";todepartid="";tocomid="";
	      			var count=0;
	      			mui.each(mui("#userlist input"),function(i,info){
	      				if(info.checked)
	      				{
	      					count++;
	      					touserid += info.value+",";
	      					str1 += info.getAttribute("val")+",";
	      				}
	      			});
	      			obj10.find("input").val(str1.TrimEnd(","));
	      			obj10.find("input").attr("touserid",touserid.TrimEnd(","));
					obj10.attr("touserid",touserid.TrimEnd(","));
	      			CloseWindow();
			});
			
			$("#contentlist6").html(CheckMate_Data());
			data = {};
			data.act = "DepartAndUser_Data";
			data.userid=userid;
			data.comid=comid;
			data.source=source;
			data.sign=GetSign(data.act);
			
			mui.getJSON(admin_domain, data, function(json) {
				Bind_CheckMate(json.data.user,json.data.depart);
				Init_CheckMate();
				
			});
			if($(this).attr("show")=="1")
	      	{
	      		$(".selectbar").hide();
	      	}else
	      	{
				$(".selectbar").show();  				
	      	}
	    });
	
    var data = {};
	data.act = "One_Library";
	data.id=$("#libraryid").attr("val");
	data.source=source;
	data.userid=userid;
	data.comid=comid;
	data.sign=GetSign(data.act);
	mui.getJSON(crm_domain, data, function (json) {
	    if (json.state) {
	    	var library=json.data;
	    	$("#txt_num").val(library.Num);
	    	$("#txt_name").val(library.Name);
	    	$("#txt_address").val(library.Address);
	    	$("#txt_manager").val(library.Manager);
	    	$("#txt_mobile").val(library.Mobile);
	    	$("#txt_bak").val(library.Bak);
	    }
	});

};

function Vote_EndTime(o) {
    if ($(o).val() == "0") {
        $("#senddate").removeClass("hidden");
    } else {
        $("#senddate").addClass("hidden");
    }
};

function Vote_Result(o){
	if ($(o).val() == "3") {
        $("#vote_seeuser").removeClass("hidden");
    } else {
        $("#vote_seeuser").addClass("hidden");
    }
};

function Cal_Option() {
    var votepanel = $("#vote_maxselect");
    votepanel.html("<option value='1'>单选</option><option value='2'>最多选2项</option>");
    var inputs = $("#votepanel .ctext input");
    var count = 2;
    $.each(inputs, function (i, info) {
        if ($(info).val().Trim() != "") {
            count++;
            votepanel.append("<option value='"+count+"'>最多选" + count + "项</option>");
        }
    });

};

function RemoveVoteOption(o){
	$(o).parent().parent().remove();
	Cal_Option();
};

function Sure_Vote() {
        var data = {};
        var vote_title = $("#vote_title");
        if(vote_title.val().Trim()=="")
        {
        	plus.nativeUI.toast("请输入投票标题");
        	return false;
        }
        if($("#option1").val().Trim()=="")
        {
        	plus.nativeUI.toast("投票项1为必填项");
            return false;
        }
        if($("#option2").val().Trim()=="")
        {
        	plus.nativeUI.toast("投票项2为必填项");
            return false;
        }
        if($("#vote_enddate").val()=="0" && $("#self_enddate").val()=="")
        {
        	plus.nativeUI.toast("请选择截止时间");
        	return false;
        }
        if($("#vote_result").val()=="3" && $("#vote_seeuser").attr("touserid")=="")
        {
        	plus.nativeUI.toast("请选择投票结果可见人");
        	return false;
        }
        $("#vote_tool").attr("hasvote","true");
        $("#votetitles").val(vote_title.val());
		CloseWindow();
};
